package com.zero.manager.mapper;

import org.apache.ibatis.annotations.*;
import com.zero.manager.entity.User;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface UserMapper {
    @Insert("insert into `user` (username, password, name, phone, email, address, avatar) values (#{username}, #{password}, #{name}, #{phone}, #{email}, #{address}, #{avatar})")
    void insert(User user);

    @Update("update `user` set username = #{username}, name = #{name}, phone = #{phone}, email = #{email}, address = #{address}, avatar = #{avatar} where id = #{id}")
    void update(User user);

    @Delete("delete from user where id = #{id}")
    void delete(Integer id);

    @Select("select * from user order by id desc")
    List<User> list();

    @Select("select * from user where id = #{id} order by id desc")
    User listById(Integer id);

    @Select("select * from user where name like concat('%',#{name},'%')")
    List<User> listLike(@Param("name") String name);

    @Select("select * from user where username like concat('%',#{username},'%') and name like concat('%',#{name},'%')" +
            " order by id desc limit #{pageNum}, #{pageSize}")
    List<User> listPage(@Param("username") String username, @Param("name") String name,
                        @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);

    @Select("select count(*) from user where username like concat('%',#{username},'%') and name like concat('%',#{name},'%')")
    Integer getTotal(@Param("username") String username, @Param("name") String name);

    @Select("select * from user where username = #{username}")
    User selByName(String username);

    @Select("select * from user where id = #{id}")
    User selById(int i);
}
